/*
 * @Description: 全宗reducer
 * @Author: Rfan
 * @Date: 2022-01-08 16:30:05
 * @LastEditTime: 2022-04-02 13:57:59
 */

import {
  HIDE_APPROVE_DIALOG,
  SET_APPROVE_LIST,
  SET_APPROVE_NAV,
  SET_QUERY,
  SHOW_APPROVE_DIALOG,
  SUBMIT_APPROVE
} from '../constants';

export const ApproveReducer = (state, action) => {
  switch (action.type) {
    // 加载表格数据及相关数据
    case SET_QUERY: {
      const approveQuery = { ...state.approveQuery };
      action.info.forEach(({ key, value }) => {
        approveQuery[key] = value;
      });

      return {
        ...state,
        approveQuery
      };
    }

    /**
     * @description: 设置利用审批列表
     * @param {*} data 列表数据
     */
    case SET_APPROVE_LIST:
      return {
        ...state,
        approveList: action.data,
        approveLoading: false
      };

    /**
     * @description: 设置利用审批导航
     * @param {*} data 列表数据
     */
    case SET_APPROVE_NAV:
      return {
        ...state,
        approveNav: action.navKey
      };

    /**
     * @description: 打开查看申请弹窗
     */
    case SHOW_APPROVE_DIALOG:
      return {
        ...state,
        approveDialog: {
          visible: true,
          data: action.data,
          type: action.dialogType
        }
      };

    /**
     * @description: 打开查看申请弹窗
     */
    case HIDE_APPROVE_DIALOG: {
      return {
        ...state,
        approveDialog: {
          visible: false,
          data: null,
          type: ''
        }
      };
    }

    /**
     * @description: 打开查看申请弹窗
     */
    case SUBMIT_APPROVE:
      return {
        ...state,
        approveDialog: {
          visible: false,
          data: null
        }
      };

    default:
      console.log('untouched', action);
      return state;
  }
};
